#ifndef __CMS_MSG_OYC0P5N4
#define __CMS_MSG_OYC0P5N4

#include <stdio.h>
#include <stdint.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>

#include <unistd.h>
#include <pthread.h>
#include <errno.h>


#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/stat.h>
#include <sys/shm.h>

#include <sys/ioctl.h>
#include <netdb.h>


#include "cms_common.h"

//void msgtestLock();
//void msgtestUnlock();



/*define max length of module name*/
#define MODULE_NAME_SIZE 128
#define DATA_SIZE	16

/*msg share mem size & defalut offset*/
#define MSG_SHM_SIZE	1024
#define MSG_OFFSET		4

#define MAX_PARA_SIZE   128
#define MAX_VALUE_SIZE  128

/*request action type*/
#define CMS_MSG_ACT_REGMODULE 			0x00000001
#define CMS_MSG_ACT_UNREGMODULE 		0x00000002
#define CMS_MSG_ACT_GETMODULEID			0x00000003
#define CMS_MSG_ACT_SEL					0x00000004
#define CMS_MSG_ACT_SELID				0x00000005
#define CMS_MSG_ACT_SELBYOFFSET			0x00000006
#define CMS_MSG_ACT_ADDOBJBYID		  	0x00000007
#define CMS_MSG_ACT_ADDOBJBYPATH		0x00000008

//#define CMS_MSG_ACT_DELOBJ		    0x00000009
#define CMS_MSG_ACT_DELOBJBYPATH		0x00000010
#define CMS_MSG_ACT_DELOBJBYID		    0x00000011

#define CMS_MSG_ACT_GETOBJ				0x00000012
#define CMS_MSG_ACT_SETPARA	  			0x00000013
#define CMS_MSG_ACT_GETPARA	  			0x00000014
#define CMS_MSG_ACT_SETATTR  			0x00000015
#define CMS_MSG_ACT_GETATTR  			0x00000016
#define CMS_MSG_ACT_SUBSCRIBEEVENT 		0x00000017
#define CMS_MSG_ACT_UNSUBSCRIBEEVENT	0x00000018
#define CMS_MSG_ACT_EVENT_NOTIFY		0x00000019
#define CMS_MSG_ACT_OBJCHG_NOTIFY		0x00000020
#define CMS_MSG_ACT_SAVE	  			0x00000021
#define CMS_MSG_ACT_RESTORDEFAULT 		0x00000022
#define CMS_MSG_ACT_RESTORECONF			0x00000023
#define CMS_MSG_ACT_PARAMETERINFO		0x00000024  /*reponse parameter info in share memory*/
#define CMS_MSG_ACT_OBJCHG_DATA			0x00000025  /*put share memory to store object which has been changed*/
#define CMS_MSG_ACT_CMD_SERVICE			0x00000026
#define CMS_MSG_ACT_UPDATE				0x00000027
#define CMS_MSG_ACT_PUT_PARAINFO		0x00000028  /*put share memeory to store parameter get by module*/
#define CMS_MSG_ACT_SET_LOG		    	0x00000029  /*set process log level*/
#define CMS_MSG_ACT_SETMODULEID			0x00000030  /*set src module id*/
#define CMS_MSG_ACT_QUEUE_CLEAN	    	0x00000031  /*when msg queue num more than max, clean unuse queue*/
#define CMS_MSG_ACT_GET_ALL_EVENT		0x00000032  /*print all app and its event info*/
#define CMS_MSG_ACT_GET_APP_EVENT		0x00000033  /*print one app and its event info*/
#define CMS_MSG_ACT_PRE_DEFAULT			0x00000034  /*download pre default file to pre partition*/
#define CMS_MSG_ACT_OBJECT_RESTORE 		0x00000035  /*object restore*/ 


/*action handle result*/
#define CMS_STATUS_SUCCESS		0
#define CMS_STATUS_FAIL		-1

/*flag definition*/
#define CMS_MSG_ACK		(1 << 31)
#define CMS_MSG_NACK	(1 << 30)
#define CMS_MSG_REQUEST (1 << 29)
#define CMS_MSG_REPLY	(1 << 28)
#define CMS_MSG_EVENT	(1 << 27)
//#define CMS_MSG_VALIDATE_FAIL (1 << 26)
#define CMS_MSG_NOREPLY	(1 << 25)
#define CMS_MSG_SEND	(1 << 24)
#define CMS_MSG_RECV    (1 << 23)

/*last 30bit for act type*/
#define MSG_ACT_TYPE_MASK	0x3FFFFFFF
#define SET_TYPE(F,T)	(F |= T & MSG_ACT_TYPE_MASK)
#define GET_TYPE(F,T)	(F = T & MSG_ACT_TYPE_MASK)
#define SET_ACK(F)		(F = ((F & ~CMS_MSG_NACK) | CMS_MSG_ACK))
#define SET_NACK(F)		(F = ((F & ~CMS_MSG_ACK) | CMS_MSG_NACK))
#define IS_ACK(F)		(F & CMS_MSG_ACK)
#define IS_NACK(F)		(F & CMS_MSG_NACK)
#define IS_REQUEST(p) 	(p->type & CMS_MSG_REQUEST)
#define IS_REPLAY(p) 	(p->type & CMS_MSG_REPLY)
#define GET_SESSIONID(p) ((p)->header.sessionId)

/*object change flag*/
#define CMS_DB_ADD_OBJECT_BIT		30
#define CMS_DB_DEL_OBJECT_BIT			31
//#define CMS_DB_DATA_OP_MASK			0xC0000000
#define CMS_DB_OBJ_SIZE_MASK 			0x00FFFFFF
#define CMS_DB_FLAG_MASK				0xFF000000
#define CMS_DB_ADD_OBJECT				(1 << CMS_DB_ADD_OBJECT_BIT)
#define CMS_DB_DEL_OBJECT				(1 << CMS_DB_DEL_OBJECT_BIT)
#define CMS_DB_SET_OBJECT				((1 << CMS_DB_ADD_OBJECT_BIT) | (1 << CMS_DB_DEL_OBJECT_BIT) )
//#define CMS_DB_SAVE_OLD_DATA			CMS_DB_DEL_OBJECT
//#define CMS_DB_SAVE_NEW_DATA		CMS_DB_ADD_OBJECT

#define SIGEVENT 46

/*reserverd index size for an indexed object*/
#define MSG_RESERVED_INDEX 6

/*poll interval(ms) for msgrcv*/
#define MSGRECV_POLLING_INTERVAL_MS 10

/*define max queue msg num, if exceed, clean msg queue*/
#define MSG_QUEUE_MAX_NUM	64	

#define EVENT_CONTENT_MAX	1280

/*task stats queue key*/
#define CMSTASK_STATS_KEY 	0x100302

typedef struct cmsMsqBuf_s{
	long int mType;
	int shmNum;
	int shmId[DATA_SIZE];
}cmsMsqBuf_t;

/*define struct for stats return info*/
typedef struct cmsStatsBuf_s{
	long int mType;
	int statsRet;
	struct timespec timeStamp; /*record the time of send message*/
}cmsStatsBuf_t;

#if 1
typedef struct eventNotify_s{
	uint32_t eventId;
	uint32_t typeSizeOfEContent;
	char eventContent[1];
}eventNotify_t;
#else
typedef struct eventNotify_s{
	uint32_t eventId;
	uint32_t typeSizeOfEContent;
	char eventContent[EVENT_CONTENT_MAX];
}eventNotify_t;
#endif

typedef struct objectNotify_s{
	uint32_t objChgShmId;
}objectNotify_t;

union notify_u{
	struct eventNotify_s eventNotify;
	struct objectNotify_s objNotify;
};

typedef struct cmsEvent_s{
	long int notifyType; 		//event notify or object changed
	union notify_u notify;
}cmsEvent_t;

typedef struct cmsModule_s{
	uint32_t pid;
	uint32_t moduleMsqId;
	uint32_t eventMsqId;
	uint8_t  sizeofModuleName;
	char 	 moduleName[1];
}cmsModule_t;

typedef struct cmsMsg_header_s{
	char	 srcPidname[32];
	char 	 srcModuleName[128];
	uint32_t srcModuleId;
	uint32_t dstModuleId;
	uint32_t sessionId;
	uint32_t actionNum;
	uint32_t len;
	uint32_t flag;
	cmsBoolean taskNotify;         //true -- notify cms_task; false --  not notify cms_task when obj changed.
	cmsBoolean cwmpNotify;     //true -- notify cwmp; false --  not notify cwmp when obj parameter changed.
	cmsBoolean isMutliObj;
	long  msgType;		      //record msg type
	struct timespec timeStamp; /*record the time of send message*/
	uint32_t reserved[4];
}cmsMsg_header_t;

typedef struct actionType_s{
	uint32_t type;
}actionType_t;

typedef struct objOffset_s{
	uint32_t id;
	uint32_t shmId;
	uint64_t IA;
}objOffset_t;

typedef struct objName_s{
	uint32_t shmId;
	uint8_t	 sizeofName;
	char	 objName[1];
}objName_t;

union object_u{
	struct objOffset_s objOffset;
	struct objName_s   objName;
};

typedef struct parameter_s{
	uint8_t	sizeofParameter;
	char parameterName[1];
}parameter_t;

typedef struct file_s{
	uint8_t sizeOfFileName;
	char fileName[1];
}file_t;

typedef struct save_s{
	uint32_t shmId;
	uint32_t pid;
}save_t;

typedef struct event_s{
	uint32_t ramId;
	uint32_t eventCount;
	uint32_t eventId[];
}event_t;

typedef struct value_s{
	uint32_t typeSizeOfValue;
	uint8_t	value[1];
}value_t;

typedef struct attr_s{
	uint32_t active;
	uint32_t attr;
	struct parameter_s parameter;
}attr_t;

typedef struct cmdService_s{
	uint32_t cmdCode;
	uint32_t typeSizeOfContent;
	char	content[1];
}cmdService_t;

typedef struct objectChgData_s{
	uint32_t realId;
	uint32_t objectId;
	uint64_t indexArry;
	uint32_t objectSize;
	char	      objValue[0];
}objectChgData_t;

typedef struct cmsMsg_action_s{
	struct actionType_s 	*action;
	union  object_u 		*object;
	struct parameter_s 	*parameter;
	struct value_s		*paraValue;
	struct attr_s 			*paraAttr;
	struct event_s 		*event;
	struct value_s 		*eventContent; 
	struct cmsModule_s 	*module; 
	struct file_s 			*file;
	struct save_s 		*save;
	struct objectNotify_s 	*objDataShm;
	struct objectChgData_s *objectData;		/*record object change data*/
	struct cmdService_s 	*cmdService;
}cmsMsg_action_t;

typedef struct cmsMsgCb_s{
	struct cmsMsgCb_s *next;
	int shmId;
	int shmCnt;
	void *shmAddr;
	uint32_t shmSize;
	int msgOffset;
	void *pCurData;
	void *pCurMsgCb;
	uint32_t msgType;
	int	length;
	struct cmsMsg_header_s header;
	struct cmsMsg_action_s action;
}cmsMsgCb_t;

typedef struct parameterInfo_s{
	char parameterName[MAX_PARA_SIZE];
	uint8_t *paraValue;
	uint32_t typeSizeOfValue;
}parameterInfo_t;

typedef struct objParaList_s{
	struct objParaList_s *prev;
	struct objParaList_s *next;
	parameterInfo_t parameter;
	int flag;
}objParaList_t;

#define RESTORE_SOURE_NONE		0x0
#define RESTORE_SOURE_CLI		0x1	//console command-line
#define RESTORE_SOURE_BUTTON	0x2
#define RESTORE_SOURE_WEB		0x3
#define RESTORE_SOURE_TR069		0x4
#define RESTORE_SOURE_DBUS		0x5
#define RESTORE_SOURE_OSGI		0x6
#define RESTORE_SOURE_OMCI		0x7
#define RESTORE_SOURE_OAM		0x8
#define RESTORE_SOURE_UBUS		0x9

#define RESTORE_TYPE_ALL		0x0
#define RESTORE_TYPE_SHORT		0x1
#define RESTORE_TYPE_LONG		0x2

#define cmsRestoreType(type) 	((type)&0x0f)
#define cmsRestoreSource(type)  (((type)&0xf0)>>4)

enum restoreType_s{
	RESTORE_ALL_NONE 		= (RESTORE_TYPE_ALL | RESTORE_SOURE_NONE<<4),
	RESTORE_SHORT_NONE 		= (RESTORE_TYPE_SHORT | RESTORE_SOURE_NONE<<4),
	RESTORE_LONG_NONE 		= (RESTORE_TYPE_LONG | RESTORE_SOURE_NONE<<4),
	RESTORE_SHORT_BUTTON 	= (RESTORE_TYPE_SHORT | RESTORE_SOURE_BUTTON<<4),
	RESTORE_LONG_BUTTON  	= (RESTORE_TYPE_LONG | RESTORE_SOURE_BUTTON<<4),
	RESTORE_SHORT_WEB 		= (RESTORE_TYPE_SHORT | RESTORE_SOURE_WEB<<4),
	RESTORE_LONG_WEB 		= (RESTORE_TYPE_LONG | RESTORE_SOURE_WEB<<4),
	RESTORE_SHORT_TR069 	= (RESTORE_TYPE_SHORT | RESTORE_SOURE_TR069<<4),
	RESTORE_LONG_TR069 		= (RESTORE_TYPE_LONG | RESTORE_SOURE_TR069<<4),
	RESTORE_SHORT_DBUS		= (RESTORE_TYPE_SHORT | RESTORE_SOURE_DBUS<<4),
	RESTORE_LONG_DBUS 		= (RESTORE_TYPE_LONG | RESTORE_SOURE_DBUS<<4),
	RESTORE_SHORT_OSGI		= (RESTORE_TYPE_SHORT | RESTORE_SOURE_OSGI<<4),
	RESTORE_LONG_OSGI 		= (RESTORE_TYPE_LONG | RESTORE_SOURE_OSGI<<4),
	RESTORE_SHORT_OMCI		= (RESTORE_TYPE_SHORT | RESTORE_SOURE_OMCI<<4),
	RESTORE_LONG_OMCI		= (RESTORE_TYPE_LONG | RESTORE_SOURE_OMCI<<4),
	RESTORE_SHORT_OAM		= (RESTORE_TYPE_SHORT | RESTORE_SOURE_OAM<<4),
	RESTORE_LONG_OAM 		= (RESTORE_TYPE_LONG | RESTORE_SOURE_OAM<<4),
	RESTORE_SHORT_UBUS		= (RESTORE_TYPE_SHORT | RESTORE_SOURE_UBUS<<4),
	RESTORE_LONG_UBUS		= (RESTORE_TYPE_LONG | RESTORE_SOURE_UBUS<<4),
};

//the different reboot reason
enum reboot_reason_e{
	//reboot
	REBOOT_NONE = 0,
	REBOOT_CLI = 1,
	REBOOT_WEB = 2,
	REBOOT_TR069 = 3,
	REBOOT_OMCI = 4,
	REBOOT_OAM = 5,
	REBOOT_DBUS = 6,
	REBOOT_OSGI = 7,
	REBOOT_WATCHDOG = 8,
	REBOOT_UBUS = 9,
    REBOOT_PON = 10,
    
	//reboot trigger by firmware upgrade
	REBOOT_TRIGGER_BY_FWUPLOAD_START = 20,
	REBOOT_WEB_FWUPLOAD,
	REBOOT_TR069_FWUPLOAD,
	REBOOT_TR069_FWUPLOAD_FAIL,
	REBOOT_OMCI_FWUPLOAD,
	REBOOT_OAM_FWUPLOAD,
	REBOOT_WEB_FWUPLOAD_FAIL,
	REBOOT_DBUS_FWUPLOAD,
	REBOOT_UBUS_FWUPLOAD,
	//reboot trigger by restore-default
	REBOOT_TRIGGER_BY_RESTORE_START = 40,
	REBOOT_NONE_RESTORE,
	REBOOT_CLI_RESTORE,
	REBOOT_BUTTON_RESTORE,
	REBOOT_WEB_RESTORE,
	REBOOT_TR069_RESTORE,
	REBOOT_DBUS_RESTORE,
	REBOOT_OSGI_RESTORE,
	REBOOT_UBUS_RESTORE,
};

#define cmsRebootReason(reason) ((reason) & 0x00ff)
#define cmsRebootType(reason)   (((reason) & 0xff00)>>8)
#define cmsRebootTriggerByFwupload(reason) (cmsRebootReason(reason) >  REBOOT_TRIGGER_BY_FWUPLOAD_START && cmsRebootReason(reason) < REBOOT_TRIGGER_BY_RESTORE_START)
#define cmsRebootTriggerByRestore(reason) ((reason) > REBOOT_TRIGGER_BY_RESTORE_START)
#define cmsRebootTriggerByRestoreLong(reason) (cmsRebootType(reason) == RESTORE_TYPE_LONG)

/*
	Describtion:
		register current process to cms_core.
	Parameter:
		moduleName -- current process name
	Return:
		not NULL - success, return a mutex;
		NULL - fail.
*/
int cms_registerModule(const char *moduleName);

/*
	Describtion:
		unregister current process to cms_core.
	Parameter:
		moduleName -- current process name
	Return:
		0 - success;
		-1 - fail.
*/
int cms_unregisterModule(const char *moduleName);


/*
	Describtion:
		get module id by name.
	Parameter:
		moduleName -- current process name
	Return:
		0 - success;
		-1 - fail.
*/
int cms_getModuleIdByName(const char *moduleName);

/*
	Describtion:
		subcribe event to cms core.
	Parameter:
		numOfEvent -- event Num
		eventId -- event ID
		sigHandle -- signal handle fun when event recv
	Return:
		0 - success;
		-1 - fail.
*/
#if 0
int	cms_subcribeEvent(uint32_t numOfEvent, const uint32_t *eventId, void (*sigHandle)(int sigNum, siginfo_t* sigInfo, void *ptr));
#else
int	cms_subcribeEvent(uint32_t numOfEvent, const uint32_t *eventId, void *(*event_rtn)(void *), void *arg);
#endif

/*
	Describtion:
		unsubcribe event to cms core.
	Parameter:
		numOfEvent -- event Num
		eventId -- event ID
	Return:
		0 - success;
		-1 - fail.
*/
int cms_unSubcribeEvent(uint32_t numOfEvent, const uint32_t *eventId);

/*
	Describtion:
		block event sigal when muti thread app subcribe eventss.
	Parameter:
		NULL
	Return:
*/
void cms_threadEventSigBlock(void);

/*
	Describtion:
		send obj para info to module who need.called by db process.
	Parameter:
		objDataMsg -- msg store shmid which store the object parameter.
		dtsModuleId -- dst module id.
	Return:
		0  -- success
		-1 -- fail
*/
int cms_objParaSent(cmsMsgCb_t *objDataMsg, uint32_t dtsModuleId);


/*
	Describtion:
		get all parameter of an object.
	Parameter:
		objId -- object offset id
		shmid -- share memory where store this object
	Return:
		return a pointer of parameter list,
		else return NULL.
*/
objParaList_t *cms_getObject(uint32_t objId, uint64_t objIA);

/*
	Describtion:
		create para list of object.
	Parameter:
		void
	Return:
		return a pointer of parameter list,
		else return NULL.

*/
objParaList_t *cms_createObjectParaList(void);

/*
	Describtion:
		free object parameter list.
	Parameter:
		paraList -- the list of object parameter.
	Return:
		-1 -- fail.
		0 -- success.
*/
int cms_freeObjectParaList(objParaList_t *paraList);


/*
	Describtion:
		set a parameter of an object.
	Parameter:
		paraList -- para list of an object
		parameter -- parameter need set
	Return:
		0  -- success
		-1 -- fail.
*/
int cms_setParameterToList(objParaList_t *paraList, char *paraName, uint32_t typeOfValue, void *value);


/*
	Describtion:
		set object parameter or del/add an object.
	Parameter:
		pathName -- object path name
		paraList -- parameter list
		replyFlag -- flag for if need cms_db to reply msg
	Return:
		0  -- success
		-1 -- fail
*/
int cms_setObjectByPathName(char *pathName, objParaList_t *paraList);

/*
	Describtion:
		notify event to cms_core
	Parameter:
		eventId -- event id
		typeSizeofContent -- type&Size of event content
		eventContent -- event content
	Return:
		0  -- success
		-1 -- fail
*/
int cms_eventNotify(uint32_t eventId, uint32_t typeSizeOfContent, void *eventContent);

/*
	Describtion:
		notify obj changed to cms_core
	Parameter:
		objDataMsg -- msg store shmid which store the object changed.
	Return:
		0  -- success
		-1 -- fail
*/
int cms_objChgNotify(cmsMsgCb_t *objDataMsg);


/*
	Describtion:
		recv event from cms_core
	Parameter:
		eventBuf -- event buf, used to recv msg
	Return:
		NULL -- fail
		not NULL -- sucess
*/
int cms_eventRecv(cmsEvent_t **eventBuf);

/*
	Describtion:
		parse header structure from msg
	Parameter:
		pMsg -- msg recv from other modules
	Return:
		NULL -- fail
		not NULL -- sucess
*/
cmsMsg_header_t *cms_parseMsgHeader(const cmsMsgCb_t *pMsg);

/*
	Describtion:
		parse action from msg
	Parameter:
		pMsg -- msg recv from other modules
	Return:
		NULL -- fail
		not NULL -- sucess
*/
cmsMsg_action_t *cms_parseMsgAction(cmsMsgCb_t *pMsg);

/*
	Describtion:
		create request msg to send other module
	Parameter:
		shmSize -- msg size. Note: if shmSize is 0, means default shmsize 1024.
	Return:
		NULL -- fail
		not NULL -- sucess
*/
cmsMsgCb_t* cms_createRequestMsg(uint32_t shmSize);

/*
	Describtion:
		create reply msg to send back to module which send request msg.
	Parameter:
		pMsg -- request msg received from other module
		status -- request msg handle result(ACK-success, NACK--fail).
	Return:
		NULL -- fail
		not NULL -- sucess
*/
cmsMsgCb_t* cms_createReplyMsg(cmsMsgCb_t *pMsg,uint32_t status);

/*
	Describtion:
		send msg to dst module.
	Parameter:
		pMsg -- msg need send to other module
		dtsId -- dst module message queue id. if dtsId is 0, send to cms_core.
	Return:
		-1 -- fail
		> 0 -- sucess   //return msg type
*/
int cms_sendMsg(cmsMsgCb_t *pMsg, uint32_t dtsId);

/*
	Describtion:
		send msg to dst module with no reply msg.
	Parameter:
		pMsg -- msg need send to other module
		dtsModuleId -- dst module message queue id. if dtsId is 0, send to cms_core.
	Return:
		-1 -- fail
		0 -- sucess
*/
int cms_sendMsgNoReply(cmsMsgCb_t *pMsg, uint32_t dtsModuleId);

/*
	Describtion:
		receive msg from other module, such as get object/param from cms_db
	Parameter:
		timeoutMs -- if 0, wait util msg recv from other module; if > 0, it's timeout time(ms).
		msgType -- msg type 
	Return:
		NULL -- fail
		not NULL -- sucess
*/
cmsMsgCb_t* cms_recvMsg(uint32_t timeoutMs, long msgType);

/*
	Describtion:
		receive msg result from other module, such as add obj or set param to cms_db
	Parameter:
		timeoutMs -- if 0, wait util msg handel result recv from other module; if > 0, it's timeout time(ms).
		msgType -- msg type 
		statsBuf -- msg handle result
	Return:
		CMS_NOK -- fail
		CMS_OK -- sucess
*/
int cms_recvMsgResult(cmsMsgCb_t *pReqMsg, uint32_t timeoutMs, cmsStatsBuf_t *statsBuf, long msgType);


/*
	Describtion:
		send msg to dts module, then recv reply msg from dst module.
	Parameter:
		pReqMsg -- request msg send to dst module
		dstModuleId -- dst module message queue id. if dtsId is 0, send to cms_core.
		timeoutMs -- if 0, wait util msg recv from other module after send msg; if > 0, it's timeout time(ms) for recv msg.
	Return:
		NULL -- fail
		not NULL -- sucess
*/
cmsMsgCb_t* cms_SendRecvMsg(cmsMsgCb_t *pReqMsg,	uint32_t dstModuleId, uint32_t timeoutMs);

/*
	Describtion:
		send msg to dts module, then recv msg handle result  from dst module.
	Parameter:
		pReqMsg -- request msg send to dst module
		dstModuleId -- dst module message queue id. if dtsId is 0, send to cms_core.
		timeoutMs -- if 0, wait util msg recv from other module after send msg; if > 0, it's timeout time(ms) for recv msg.
	Return:
		CMS_NOK -- fail
		CMS_OK -- sucess
*/
int cms_SendRecvMsgResult(cmsMsgCb_t *pReqMsg, uint32_t dstModuleId, uint32_t timeoutMs);


/*
	Describtion:
		free msg but not free share memory
	Parameter:
		pMsg -- msgCb need to free.
	Return:
		-1 -- fail
		0 -- sucess
*/
int cms_msgFree(cmsMsgCb_t *pMsg);

/*
	Describtion:
		when send msg fail, free msg and share memory.
	Parameter:
		pMsg -- msgCb need to free.
	Return:
		-1 -- fail
		0 -- success
*/
int cms_msgAndShmFree(cmsMsgCb_t *pMsg);

uint32_t genKeyByName(const char *moduleName, int *cmsModuleKey, int *cmsEventKey);

/*reqiest api*/
int cms_requestRegModule(cmsMsgCb_t *pMsg, const char *moduleName, uint32_t pid, uint32_t moduleMsqId, uint32_t eventMsqId);
int cms_requestUnRegModule(cmsMsgCb_t *pMsg, const char *moduleName);
int cms_requestGetModuleId(cmsMsgCb_t *pMsg, char *moduleName);
int cms_requestSelObjByName(cmsMsgCb_t *pMsg, char *objName);
int cms_requestSelObjById(cmsMsgCb_t *pMsg, uint32_t objId, uint64_t objIA);
int cms_requestSelObjByOffset(cmsMsgCb_t *pMsg, cmsoffset_t objOffset);

int cms_requestAddObjectByOID(cmsMsgCb_t *pMsg, uint32_t OID, uint64_t objIA);
int cms_requestAddObjectByPath(cmsMsgCb_t *pMsg, char *objPathName);
int cms_requestDelObjectByOID(cmsMsgCb_t *pMsg, uint32_t OID, uint64_t objIA);
int cms_requestDelObjectByPath(cmsMsgCb_t *pMsg, char *objPathName);

int cms_requestGetObject(cmsMsgCb_t *pMsg, uint32_t objId, uint64_t objIA);
int cms_requestSetPara(cmsMsgCb_t *pMsg, char *parameter, uint32_t typeSizeOfValue, void *value);
int cms_requestGetPara(cmsMsgCb_t *pMsg, char *parameter);
int cms_requestSetAttr(cmsMsgCb_t *pMsg, char *parameter, uint32_t attr, uint32_t active);
int cms_requestGetAttr(cmsMsgCb_t *pMsg, char *parameter);
int cms_requestSubscribeEvent(cmsMsgCb_t *pMsg, uint32_t numOfEvent, const uint32_t *eventId);
int cms_requestUnsubscribeEvent(cmsMsgCb_t *pMsg, uint32_t numOfEvent, const uint32_t *eventId);
int cms_requestEventNotify(cmsMsgCb_t *pMsg, uint32_t eventId, uint32_t typeSizeOfContent, void *eventContent);
int cms_requestObjChgNotify(cmsMsgCb_t *pMsg, cmsMsgCb_t *objDataMsg);
int cms_requestObjChange(cmsMsgCb_t *pMsg, uint32_t realID, uint32_t objId, uint64_t objIA, uint32_t flag, uint32_t objSize, void *oldObjData, void *newObjData );

int cms_requestParaInfo(cmsMsgCb_t *pMsg, char *parameterName, uint32_t typeSizeOfValue, void *value);
int cms_setSaveActionRequest(cmsMsgCb_t *pMsg, uint32_t shmId);
int cms_requestRestoreDefault(cmsMsgCb_t *pMsg, uint32_t type);
int cms_requestRestoreConf(cmsMsgCb_t *pMsg, char *fileName);
int cms_requestPutPara(cmsMsgCb_t *pMsg, cmsMsgCb_t *objParaMsg);
int cms_requestUpdate(cmsMsgCb_t *pMsg, uint32_t objId, uint64_t odjIA);
int cms_requestSetLog(cmsMsgCb_t *pMsg, uint32_t logLevel);
int cms_requestSetModuleId(cmsMsgCb_t *pMsg, uint32_t srcModuleId);
int cms_requestQueueClean(cmsMsgCb_t *pMsg);
int cms_requestGetAppEvent(cmsMsgCb_t *pMsg, char *moduleName);
int cms_requestMsg(cmsMsgCb_t *pMsg, int requestType);
int cms_requestSavePreConf(cmsMsgCb_t *pMsg, char *fileName);
int cms_requestObjRestore(cmsMsgCb_t *pMsg, cmsoffset_t objOffset, uint32_t restoreType);
void cms_cleanZombieMsg(void);




#endif /* end of include guard: __CMS_MSG_OYC0P5N4 */
